package com.zhentao.controller;

import com.zhentao.pojo.WxUser;
import com.zhentao.service.WxUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;


@RestController
@RequestMapping("/wxUser")
public class WxUserController {


    @Autowired
    private WxUserService wxUserService;

    @PostMapping("/login")
    public Map<String, Object> login(@RequestBody Map<String, String> params) {
        String code = params.get("code");
        String nickname = params.get("nickname");
        String avatarUrl = params.get("avatarUrl");
        System.out.println("code=" + code);
        System.out.println("nickname=" + nickname);
        System.out.println("avatarUrl=" + avatarUrl);

        WxUser user = wxUserService.login(code, nickname, avatarUrl);
        System.out.println("user=" + user);
        Map<String, Object> result = new HashMap<>();
        result.put("code", 200);
        result.put("msg", "登录成功");
        result.put("data", user);
        return result;
    }




}
